#include "ccms/nr/node_stats.h"
#include "arlib/exception/errno_exception.h"
#include <cstdio>
#include <cstdlib>

using namespace ccms::nr;

int main(int argc, char* argv[])
{
    NodeStats nodeStats;
    int N = 1000;

    try {
        while(N--) {
            nodeStats.update();
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_USER);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_NICE);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_SYSTEM);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_IDLE);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_IOWAIT);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_IRQ);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_SOFTIRQ);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_STEAL);
            nodeStats.getTotalCpuUsage(CPU_USAGE_MODE_GUEST);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_PHYS_TOTAL);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_PHYS_FREE);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_PHYS_BUFFERS);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_PHYS_CACHED);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_PHYS_USED);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_SWAP_TOTAL);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_SWAP_FREE);
            nodeStats.getTotalMemUsage(MEM_USAGE_MODE_SWAP_USED);
        }
    }
    catch(arlib::exception::ErrnoException& e) {
        printf("Exception in file: %s, line: %d\n", e.getExceptionFile(), e.getExceptionLine());
        printf("Exception reason: %s\n", e.what());
        printf("Exception errnum: %d\n", e.getErrnum());
        return 1;
    }
    catch(arlib::exception::Exception& e) {
        printf("Exception in file: %s, line: %d\n", e.getExceptionFile(), e.getExceptionLine());
        printf("Exception reason: %s\n", e.what());
        return 1;
    }
    return 0;
}
